package sms

import (
	"admin.supervise.limaochuxing.top/admin/schemas/req"
	"admin.supervise.limaochuxing.top/admin/service/sms"
	"admin.supervise.limaochuxing.top/core"
	"admin.supervise.limaochuxing.top/core/response"

	"admin.supervise.limaochuxing.top/util"

	"fmt"

	"github.com/gin-gonic/gin"
)

var SmsGroup = core.Group("/sms", newSmsHandler, regSms)

func newSmsHandler(srv sms.ISmsService) *smsHandler {
	return &smsHandler{srv: srv}
}

func regSms(rg *gin.RouterGroup, group *core.GroupBase) error {
	return group.Reg(func(handle *smsHandler) {
		rg.POST("/send-login-code", handle.sendLoginCode)
	})
}
type smsHandler struct {
	srv sms.ISmsService
}
func (s smsHandler) sendLoginCode(c *gin.Context) {
	var req req.SMSSendLoginCodeReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &req)) {
		return
	}
	data,err := s.srv.SendLoginCode(req.Account)
	fmt.Println(data,err)
	response.CheckAndRespWithData(c,data,err)
}